﻿namespace _2.策略模式;

/// <summary>
/// 声明一个收取现金的抽象类
/// </summary>
public abstract class CashSuper
{
    public abstract double AcceptCash(double money);
}

/// <summary>
/// 重写父类中收取现金方法
/// </summary>
public class CashNormal : CashSuper
{
    public override double AcceptCash(double money)
    {
        return money;
    }
}

/// <summary>
/// 重写父类中收取现金方法
/// </summary>
public class CashRebate : CashSuper
{
    private double moneyRebate = 1d;

    public CashRebate(string moneyRebate)
    {
        this.moneyRebate = double.Parse(moneyRebate);
    }

    public override double AcceptCash(double money)
    {
        return money * moneyRebate;
    }
}

/// <summary>
/// 重写父类中收取现金方法
/// </summary>
public class CashReturn : CashSuper
{
    private double moneyCondition = 0.0d;
    private double moneyReturn = 0.0d;

    public CashReturn(string moneyCondition, string moneyReturn)
    {
        this.moneyCondition = double.Parse(moneyCondition);
        this.moneyReturn = double.Parse(moneyReturn);
    }

    public override double AcceptCash(double money)
    {
        double result = money;
        if (money >= moneyCondition)
        {
            result = money - Math.Floor(money / moneyCondition) * moneyReturn;
        }
        return result;
    }
}




